/**
 * @param {Function|string|object} rule
 * @param {*} value
 * @returns {undefined|string}
 */
export default function onValidationHandle(rule, value) {
	const objectRuleType = {
		array() {
			if (value == "") {
				return rule.message || "有必填项未填"
			}
			if (!isArray(value)) {
				return `${value}: 不是数组`
			}
			if (!value.length) {
				return rule.message || "有必填项未填"
			}
		},
		mobile() {
			const validationValue = value + ""
			if (validationValue.length != 11 || validationValue[0] != 1) {
				return rule.message || "手机号有误"
			}
		},
		password() {
			if (value == "") {
				return rule.message || "密码不能为空"
			}
			if (value !== rule.password) {
				return "两次密码不一致"
			}
		},
	}
	const ruleTypeof = {
		function() {
			const error = rule(value)
			if (error) {
				return error
			}
		},
		string() {
			const validationValue = value + ""
			if (
				validationValue == "" ||
				validationValue == "null" ||
				validationValue == "undefined"
			) {
				return rule || "有必填项未填"
			}
		},
		object() {
			return objectRuleType[rule.type] && objectRuleType[rule.type]()
		},
	}

	return ruleTypeof[typeof rule] && ruleTypeof[typeof rule]()
}
